﻿using System;
using System.Xml;

namespace SDT.CrawlSystem.Servers.Filters
{
    /// <summary>
    /// Written by TungNX
    /// </summary>
    public sealed class Txt
    {
        public string StartWith = null;
        public int StartAt = 0;
        public string EndWith = null;

        public int MaxLength = 0;

        public Txt(XmlNode n)
        {
            if (n == null)
                throw new ArgumentNullException();

            if (n.Attributes["StartAt"] != null)
                try
                {
                    StartAt = Convert.ToInt32(n.Attributes["StartAt"].Value.Trim());
                }
                catch { }

            if (n.SelectSingleNode("StartWith") != null)
                StartWith = n.SelectSingleNode("StartWith").InnerText;

            if (n.SelectSingleNode("EndWith") != null)
                EndWith = n.SelectSingleNode("EndWith").InnerText;

            if (n.SelectSingleNode("MaxLength") != null)
                try
                {
                    MaxLength = Convert.ToInt32(n.SelectSingleNode("MaxLength").InnerText);
                    MaxLength = MaxLength > 0 ? MaxLength : 0;
                }
                catch { }
        }
    }
}